home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mac Mania 4
/
MacMania 4.toast
/
/
Demo's
/
Igor Demo Pro
/
3 PutContentsIn Igor Pro Folder
/
Technical Notes
/
Igor Tech Notes
/
TN006 DSP support
/
FTMagPhase TEXT
< prev
next >
Wrap
Text File
|
1992-03-02
|
3KB
|
131 lines
Function log2(val)
variable val
return ln(val)/ln(2)
end
Function CeilPwr2(x)
variable x
return 2^(ceil(log2(x)))
end
| brings the first graph window containing the given wave to the front. If no such window is found
| then one is created.
Proc BringDestFront(w)
string w
string win
variable winIndex,didit=0
CheckDisplayed /A $w
if(V_flag) | if displayed somewhere, need to know if is graph & bring to front if so
do
win=WinName(winIndex, 1) | name of top graph window
if( cmpstr(win,"") == 0 )
break; | no more graph wndows
endif
DoWindow /F $win
CheckDisplayed $w
if(V_Flag)
didit= 1
break
endif
winIndex += 1
while(1) | exit via break
endif
if(!didit)
Display $w | if not displayed anywhere then ok to create a new window
endif
end
| Given an input wave ( doesn't have to be a power of two), create a new wave
| with the suffix "_Mag" that contains the normalized frequency response and
| optionally a wave with the suffix "_Phase".
| Several levels of resolution enhancement (really just sin x/x interpolation)
| are provided.
| Options include windowing (Hann) vs no windowing, linear vs dB,
| phase vs no phase
| If phase then option of radians or degrees,wrapped or unwrapped
| You may want to modify the code at the end of this macro.
| It sets the display style and that is a matter of taste.
| REQUIRES: BringDestFront(),CeilPwr2()
|
Macro FTMagPhase(w,window,resolution,linlog,phase,phasetype)
string w
Prompt w,"Input data:",popup WaveList("*",";","")
variable window=1
Prompt window,"Windowing:",popup "None;Hann"
variable resolution=1
Prompt resolution,"Resolution enhancement:",popup "none;2;4;8;16;32"
variable linlog= 2
Prompt linlog,"Magnitude mode:",popup "Linear;dB"
Variable phase= 1
Prompt phase,"Phase:",popup "No phase;Phase in radians;Phase in degrees"
Variable phasetype=1
Prompt phasetype,"Unwrap phase?",popup,"No;Yes"
;
PauseUpdate; Silent 1
string destw=w+"_Mag",phasew= w+"_Phase"
Variable n= numpnts($w)
if( (resolution<1) %| (resolution>6) )
Abort "resolution out of range"
endif
resolution -= 1
Duplicate/O $w $destw
if(window==2)
Hanning $destw; $destw *= 2 | assumes continuous rather than pulsed data
endif
Redimension/N=(CeilPwr2(n)*2^resolution) $destw | pad with zeros to power of 2
fft $destw
$destw= r2polar($destw)
| NOTE: depending on your application you may want to un-comment the next line
| $destw[0] /= 2 | dc is special
if( phase!=1 )
Duplicate/O $destw $phasew
Redimension/R $phasew
$phasew= imag($destw)
if( phasetype==2 )
$phasew[0]= $phasew[1] | try to avoid glitch at dc
UnWrap 2*Pi,$phasew
$phasew[0]= 0
endif
if(phase==3)
$phasew *= 180/Pi
SetScale y,0,0,"deg",$phasew
else
SetScale y,0,0,"rad",$phasew
endif
endif
Redimension/R $destw
if( linlog==2 )
WaveStats/Q $destw
$destw= 20*log($destw/V_max)
SetScale y,0,0,"dB",$destw
else
$destw /= n/2
SetScale y,0,0,"V",$destw
endif
BringDestFront(destw)
if( phase!=1 )
CheckDisplayed $phasew
if( !V_Flag )
Append/R $phasew
endif
endif
if( numpnts($destw) <= 129 )
Modify mode($destw)=4,marker($destw)=19,msize($destw)=1
else
Modify mode($destw)=0
endif
end